<template>
  <div class="amendid-box">
    <div class="addid-from">
      <TitleHeader name="修改密码"></TitleHeader>
      <p>
        <span style="margin-left: 32px">原密码</span
        ><el-input v-model="oldpasswrod" style="width: 400px"></el-input>
      </p>
      <p>
        <span style="margin-left: 32px">新密码</span>
        <el-input v-model="newpasswrod" show-password style="width: 400px" ></el-input></p>
      <p>
        <span>确认新密码</span>
        <el-input v-model="affirmpasswrod" show-password style="width: 400px"></el-input>
      </p>
      <p class="addid-btn">
        <el-button type="primary" @click="changepsd">修改</el-button>
        <el-button>重置</el-button>
      </p>
    </div>
  </div>
</template>

<script>
import TitleHeader from '../../../components/TitleHeader';
import { psdchange,detectionuser } from "@/apis/user";

export default {
  data() {
    return {
      id:sessionStorage.getItem("user"),
      oldpasswrod: "",
      newpasswrod: "",
      affirmpasswrod: "",
    };
  },
  methods:{
    changepsd(){
      if(!this.oldpasswrod||!this.newpasswrod||!this.affirmpasswrod){
        this.$message.error({message:'输入框不能为空哦!',center: true});
        return
      }
      if(this.affirmpasswrod===this.newpasswrod){
        this.$confirm('是否确定修改密码,修改以后不能还原, 是否继续?', '提示', {confirmButtonText: '确定',cancelButtonText: '取消',type:'warning'
          }).then(() => {
           detectionuser({oldPwd:this.oldpasswrod,id:this.id}).then(res=>{
             if(res.data.code==0){
            psdchange({newPwd:this.newpasswrod,id:this.id}).then(res=>{
                 if(res.data.code==0){
                     this.$message({message: '臭臭世界系统提示:修改成功!',center: true,type:'success'});
                     this.$router.push("/"); 
                   }
           });
             }else{
               this.$message.error({message:'错了哦，新密码和旧密码不一至',center: true});
             }
             })
     
           }).catch(() => {
               this.$message({message: '臭臭世界系统提示:取消成功!',center: true,type:'success'})
           });
      }else{
        this.$message.error({message:'错了哦，两次的密码不一样',center: true});
      }
    }
  },
  components:{
    TitleHeader,
  }
};
</script>

<style lang="less" scoped>

.addid-from {
  background: #fff;
  
  p {
    margin-bottom: 20px;
    padding: 0 60px;
    span {
      margin-right: 10px;
    }
  }
  .addid-btn {
    padding-left: 118px;
  }
}
</style>

   



        